<template>
  <div>
    <Search :search="search" :reset="reset">
      <template v-slot:body>
        <el-form-item label="工艺流程代号" prop="pflcode">
          <el-input v-model="query.pflcode" name="pflcode" clearable />
        </el-form-item>

        <el-form-item label="工艺流程名称" prop="processname">
          <el-input v-model="query.processname" name="processname" clearable />
        </el-form-item>

        <el-form-item label="描述" prop="description">
          <el-input v-model="query.description" name="description" clearable />
        </el-form-item>
      </template>
    </Search>
    <div class="table-default">
      <Operate :show="open" />
      <el-table :data="tableData" class="mt-3" v-loading="loading" border>
        <el-table-column prop="id" label="行号" />
        <el-table-column prop="pflcode" label="工艺流程代号" min-width="120" />
        <el-table-column prop="processname" label="工艺流程名称" min-width="150" />
        <el-table-column prop="description" label="描述" min-width="150" />
        <el-table-column prop="creator_id" label="创建者" min-width="150" />
        <el-table-column prop="created_at" label="创建时间" min-width="150" />
        <el-table-column prop="modifier" label="修改者" min-width="150" />
        <el-table-column prop="updated_at" label="修改时间" min-width="150" />

        <el-table-column label="操作"  fixed="right" min-width="100">
          <template #default="scope">
            <!-- <Icon name="wrench-screwdriver" class="w-3 mr-1" /> -->
            <!-- <el-button type="success" size="small" @click="editHandler(scope.row)">编辑</el-button> -->
            <Update @click="open(scope.row.id)" />
          </template>
        </el-table-column>
      </el-table>
      <Paginate />
    </div>

    <Dialog v-model="visible" :title="title" destroy-on-close>
      <Create @close="close(reset)" :primary="id" :api="api" :processdataList="processdataList" />
    </Dialog>
  </div>
</template>

<script lang="ts" setup>
import { computed, onMounted, ref } from 'vue'
import Create from './create.vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useOpen } from '/admin/composables/curd/useOpen'
import http from '/admin/support/http'

const api = 'promanagement/processflow'

const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()

const tableData = computed(() => data.value?.data)

const processdataList = ref([])
let currRow = reactive({})
const editHandler = (item) => {
  currRow = item
}
const getProcessdata = () => {
  http.get('promanagement/processdata').then(r => {
    let list = r.data.data
    list.forEach(item => {
      item.purchaseorder_id = item.id
    })
    console.log(list)

    processdataList.value = list
  })
}

getProcessdata()

console.log(processdataList)

onMounted(() => {
  search()
  deleted(reset)
})
</script>
